

********************************************************************************
* Table 2: Daily Decomposition of the 3-day FOMC window
********************************************************************************

*********************************
* (A) 10y Treasury yield (GSW)
*********************************

use "../data/final_data_fed_secular_decline", clear

keep if date > mdy(1,1,1980)
drop if date >= mdy(7,1,2021)

*3-day FOMC window indicator
generate fomc = 1 if !missing(fomc_meet[_n+1]) | !missing(fomc_meet) | !missing(fomc_meet[_n-1])
replace fomc = 0 if missing(fomc)

*Single day indicator
generate pre_fomc= !missing(fomc_meet[_n+1])
generate day_fomc= !missing(fomc_meet)
generate day_after = !missing(fomc_meet[_n-1])

local yield "sveny10_chg"

**Treasury yield for 1980-1990
preserve	
	 keep if date < mdy(1,1,1990)
	 quietly sum `yield' if pre_fomc == 1
	 display "`r(sum)'"
	 quietly matrix eighties= `r(sum)'
	 quietly sum `yield' if day_fomc == 1
	 display "`r(sum)'"
	 quietly matrix eighties = eighties ,  `r(sum)'
	 quietly sum `yield' if day_after == 1
	 display "`r(sum)'"
	 quietly matrix eighties = eighties ,  `r(sum)'
	 quietly sum `yield' if fomc == 0
	 display "`r(sum)'"
	 quietly matrix eighties = eighties ,  `r(sum)'
	 quietly sum `yield'
	 display "`r(sum)'"
	 quietly matrix eighties = eighties ,  `r(sum)'
restore 

**Treasury yield for 1990-2000
preserve	
	 keep if date >= mdy(1,1,1990)
	 keep if date < mdy(1,1,2000)
	 quietly sum `yield' if pre_fomc == 1
	 display "`r(sum)'"
	 quietly matrix nineties = `r(sum)'
	 quietly sum `yield' if day_fomc == 1
	 display "`r(sum)'"
	 quietly matrix nineties = nineties , `r(sum)'
	 quietly sum `yield' if day_after == 1
	 display "`r(sum)'"
	 quietly matrix nineties = nineties , `r(sum)' 
	 quietly sum `yield' if fomc == 0
	 display "`r(sum)'"
	 quietly matrix nineties = nineties , `r(sum)'
	 quietly sum `yield'
	 display "`r(sum)'"
	 quietly matrix nineties = nineties , `r(sum)'

restore 

**Treasury yield for 2000 - 2010
preserve	
	 keep if date >= mdy(1,1,2000)
	 keep if date < mdy(1,1,2010)
	 quietly sum `yield' if pre_fomc == 1
	 display "`r(sum)'"
	 quietly matrix aughts = `r(sum)'
	 quietly sum `yield' if day_fomc == 1
	 display "`r(sum)'"
	 quietly matrix aughts = aughts , `r(sum)'
	 quietly sum `yield' if day_after == 1
	 display "`r(sum)'"
	 quietly matrix aughts = aughts , `r(sum)'
	 quietly sum `yield' if fomc == 0
	 display "`r(sum)'"
	 quietly matrix aughts = aughts , `r(sum)'
	 quietly sum `yield'
	 display "`r(sum)'"
	 quietly matrix aughts = aughts , `r(sum)'
restore 

**Treasury yield for 2010 - 2021
preserve	
	 keep if date >= mdy(1,1,2010)
	 quietly sum `yield' if pre_fomc == 1
	 display "`r(sum)'"
	 quietly matrix twenty_tens = `r(sum)'
	 quietly sum `yield' if day_fomc == 1
	 display "`r(sum)'"
	 quietly matrix twenty_tens = twenty_tens , `r(sum)'
	 quietly sum `yield' if day_after == 1
	 display "`r(sum)'"
	 quietly matrix twenty_tens = twenty_tens , `r(sum)'
	 quietly sum `yield' if fomc == 0
	 display "`r(sum)'"
	 quietly matrix twenty_tens = twenty_tens , `r(sum)'
	 quietly sum `yield'
	 display "`r(sum)'"
	 quietly matrix twenty_tens = twenty_tens , `r(sum)'
restore 

**Combine all of the matrices into one table
quietly matrix yields = eighties \ nineties \ aughts \ twenty_tens 

**round and format the numbers 
matmap yields yields_format, map(round(@, 0.01))

**Create a sum value for columns 1-3
matrix colsum = J(1, 5, 0)
forvalues j=1/3{
	local sum = 0
	forvalues i = 1/4{
		matrix yields_val = yields_format[`i', `j']
		scalar val = yields_val[1,1]
		local sum = `sum' + val
	}
	
	matrix colsum[1,`j'] = `sum'
}

**Combine all of the matrices into one table
quietly matrix yields_sum = yields_format \ colsum 

**Create columns and row names 
quietly matrix rownames yields_sum = "1980-1990" "1990-2000" "2000-2010" "2010-2021" "Sum"
quietly matrix colnames yields_sum= "t-1" "t" "t+1" "Other Days" "All Days"

mat list yields_sum, format("%3.2f")
esttab matrix(yields_sum) using "../tables/table2_parta.csv", replace


*********************************
* (B) 10y Treasury yield (Bloomberg)
*********************************

use "../data/final_data_fed_secular_decline", clear

keep if date > mdy(1,1,1980)
drop if date >= mdy(7,1,2021)

*3-day FOMC window indicator
generate fomc = 1 if !missing(fomc_meet[_n+1]) | !missing(fomc_meet) | !missing(fomc_meet[_n-1])
replace fomc = 0 if missing(fomc)

*Single day indicator
generate pre_fomc= !missing(fomc_meet[_n+1])
generate day_fomc= !missing(fomc_meet)
generate day_after = !missing(fomc_meet[_n-1])

local yield "usgg10_chg"

**Treasury yield for 1980- 1990
preserve	
	 keep if date < mdy(1,1,1990)
	 quietly sum `yield' if pre_fomc == 1
	 display "`r(sum)'"
	 quietly matrix bbg_eighties = `r(sum)'
	 quietly sum `yield' if day_fomc == 1
	 display "`r(sum)'"
	 quietly matrix bbg_eighties = bbg_eighties , `r(sum)'
	 quietly sum `yield' if day_after == 1
	 display "`r(sum)'"
	 quietly matrix bbg_eighties = bbg_eighties , `r(sum)'
	 quietly sum `yield' if fomc == 0
	 display "`r(sum)'"
	 quietly matrix bbg_eighties = bbg_eighties , `r(sum)'
	 quietly sum `yield'
	 display "`r(sum)'"
	 quietly matrix bbg_eighties = bbg_eighties , `r(sum)'
restore 

**Treasury yield for 1990 - 2000
preserve	
	 keep if date >= mdy(1,1,1990)
	 keep if date < mdy(1,1,2000)
	 quietly sum `yield' if pre_fomc == 1
	 display "`r(sum)'"
	 quietly matrix bbg_nineties = `r(sum)'
	 quietly sum `yield' if day_fomc == 1
	 display "`r(sum)'"
	 quietly matrix bbg_nineties = bbg_nineties , `r(sum)'
	 quietly sum `yield' if day_after == 1
	 display "`r(sum)'"
	 quietly matrix bbg_nineties = bbg_nineties , `r(sum)'
	 quietly sum `yield' if fomc == 0
	 display "`r(sum)'"
	 quietly matrix bbg_nineties = bbg_nineties , `r(sum)'
	 quietly sum `yield'
	 display "`r(sum)'"
	 quietly matrix bbg_nineties = bbg_nineties , `r(sum)'
restore 

**Treasury yield for 2000-2010
preserve	
	 keep if date >= mdy(1,1,2000)
	 keep if date < mdy(1,1,2010)
	 quietly sum `yield' if pre_fomc == 1
	 display "`r(sum)'"
	 quietly matrix bbg_aughts = `r(sum)'
	 quietly sum `yield' if day_fomc == 1
	 display "`r(sum)'"
	 quietly matrix bbg_aughts = bbg_aughts , `r(sum)'
	 quietly sum `yield' if day_after == 1
	 display "`r(sum)'"
	 quietly matrix bbg_aughts = bbg_aughts , `r(sum)'
	 quietly sum `yield' if fomc == 0
	 display "`r(sum)'"
	 quietly matrix bbg_aughts = bbg_aughts , `r(sum)'
	 quietly sum `yield'
	 display "`r(sum)'"
	 quietly matrix bbg_aughts = bbg_aughts , `r(sum)'
restore 

**Treasury yield for 2010-2021
preserve	
	 keep if date >= mdy(1,1,2010)
	 quietly sum `yield' if pre_fomc == 1
	 display "`r(sum)'"
	 quietly matrix bbg_twenty_tens = `r(sum)'
	 quietly sum `yield' if day_fomc == 1
	 display "`r(sum)'"
	 quietly matrix bbg_twenty_tens = bbg_twenty_tens,  `r(sum)'
	 quietly sum `yield' if day_after == 1
	 display "`r(sum)'"
	 quietly matrix bbg_twenty_tens = bbg_twenty_tens,  `r(sum)'
	 quietly sum `yield' if fomc == 0
	 display "`r(sum)'"
	 quietly matrix bbg_twenty_tens = bbg_twenty_tens,  `r(sum)'
	 quietly sum `yield'
	 display "`r(sum)'"
	 quietly matrix bbg_twenty_tens = bbg_twenty_tens,  `r(sum)'
restore 

**Combine all of the matrices into one table
quietly matrix bbg_yields = bbg_eighties \ bbg_nineties \ bbg_aughts \ bbg_twenty_tens 

**round and format the numbers 
matmap bbg_yields bbg_yields_format, map(round(@, 0.01))

**Create a sum value for columns 1-3
matrix bbg_colsum = J(1, 5, 0)
forvalues j=1/3{
	local sum = 0
	forvalues i = 1/4{
		matrix bbg_yields_val = bbg_yields_format[`i', `j']
		scalar val = bbg_yields_val[1,1]
		local sum = `sum' + val
	}
	
	matrix bbg_colsum[1,`j'] = `sum'
}

**Combine all of the matrices into one table
quietly matrix bbg_yields_sum = bbg_yields_format \ bbg_colsum 

**Create columns and row names 
quietly matrix rownames bbg_yields_sum = "1980-1990" "1990-2000" "2000-2010" "2010-2021" "Sum"
quietly matrix colnames bbg_yields_sum= "t-1" "t" "t+1" "Other Days" "All Days"

mat list bbg_yields_sum, format("%3.2f")
esttab matrix(bbg_yields_sum) using "../tables/table2_partb.csv", replace
